<?php

/** @var \Laravel\Lumen\Routing\Router $router */

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$api = app('Dingo\Api\Routing\Router');

$api->version('v1', [
    'namespace' => 'App\Http\Controllers\Admin\V1',
    // 'middleware' => 'cors'
], function ($api) {
    $api->group([
        // 'middleware' => [''],
        'limit'   => config('api.rate_limits.sign.limit'),
        'expires' => config('api.rate_limits.sign.expires'),
    ], function ($api) {
        $api->get('/', function () use ($api) {
            return 'error';
        });

        //登录
        $api->post('login', 'AuthorizationsController@store');
        // 刷新token
        $api->post('token/update', 'AuthorizationsController@update');
        // 退出
        $api->post('logout', 'AuthorizationsController@destroy');

        $api->get('getMarketData', 'StockController@getMarketData');


        //需要token验证的接口
        $api->group(['middleware' => ['auth:admin']], function ($api) {

            $api->get('getInfo', 'AdminController@getInfo');


            // nav
            $api->get('nav', 'NavController@index');
            $api->get('nav/set/noCache', 'NavController@navSetNoCache');
            $api->get('nav/set/affix', 'NavController@navSetAffix');

            // 权限
            $api->get('permission/index', 'PermissionController@index');
            $api->get('permission/show', 'PermissionController@show');
            $api->get('permission/tree', 'PermissionController@indexTree');
            $api->post('permission/drop', 'PermissionController@drop');
            $api->post('permission/create', 'PermissionController@create');
            $api->post('permission/update', 'PermissionController@update');
            $api->post('permission/delete', 'PermissionController@delete');


            // 角色
            $api->get('role/index', 'RoleController@index');
            $api->get('role/show', 'RoleController@show');
            $api->get('role/all', 'RoleController@allIndex');
            $api->post('role/create', 'RoleController@create');
            $api->post('role/update', 'RoleController@update');
            $api->post('role/delete', 'RoleController@delete');
            $api->post('role/syncPermissions', 'RoleController@syncPermissions');
            $api->post('role/syncRoles', 'RoleController@syncRoles');

            // 管理员
            $api->get('admin/index', 'AdminController@index');
            $api->get('admin/show', 'AdminController@show');
            $api->post('admin/create', 'AdminController@create');
            $api->post('admin/update', 'AdminController@update');
            $api->post('admin/delete', 'AdminController@delete');
            $api->post('admin/syncPermissions', 'AdminController@syncPermissions');

            // 研报社
            $api->get('stock_article/index', 'StockArticleController@index');
            $api->get('stock_article/detail', 'StockArticleController@detail');

            $api->get('stock/index', 'StockController@index');
            $api->post('stock/create', 'StockController@create');
            $api->get('stock/getMarketData', 'StockController@getMarketData');

            $api->get('my_stock/index', 'MyStockController@index');


            // nginx
            $api->get('nginx/index', 'NginxsController@index');

            // 异常
            $api->get('exception/index', 'ExceptionErrorController@index');
            $api->post('exception/amended', 'ExceptionErrorController@amended');
            $api->get('exception/files', 'ExceptionErrorController@files');
            $api->get('exception/file', 'ExceptionErrorController@file');

            // 文件
            $api->get('files', 'FileSystemController@files');
            $api->post('files/makeDirectory', 'FileSystemController@makeDirectory');
            $api->post('files/deleteDirectory', 'FileSystemController@deleteDirectory');
            $api->post('files/upload', 'FileSystemController@upload');
            // $api->post('files/uploadUnPermission', 'FileSystemController@uploadUnPermission');
            $api->post('files/download', 'FileSystemController@download');
            $api->post('files/delete', 'FileSystemController@delete');

            // 采集
            $api->get('kkweb', 'CollectController@kkWeb');


        });
    });


    //Test 获取API版本
    $api->get('version', function () {
        return response()->json(response_success_msg('this is version v1'));
    });


});


$api->version('v2', function ($api) {
    $api->get('version', function () {
        return response()->json(response_success_msg('this is version v2'));
    });
});


//兜底路由
//屏蔽错误路由
$router->addRoute(['POST', 'GET', 'OPTIONS'], '{url:.*}', function ($url) {
    return response_error_msg($url . ' not exist');
});
